import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';

export namespace PerBusinessPostExperienceApi {
  /** 岗位情况业务信息信息 */
  export interface BusinessPostExperience {
    id: number; // 主键ID
    busiId?: string; // 业务主表id
    employeeId?: number; // 人员ID，对应 per_employee.id
    eduPostId: number; // 教育经历ID
    postUnit: string; // 任职单位
    startDate: string | Dayjs; // 开始时间
    endDate: string | Dayjs; // 结束时间
    postType: string; // 岗位类别
    postLevel: string; // 岗位等级
    postFile: string; // 任职文件
    status: number; // 是否有效（1：有效，0：无效）
    remarks: string; // 备注
    changeType: string; // 变更类型（add：新增，update：修改，delete：删除）
    changeContent: string; // 变更内容(JSON格式，记录变更前后对比，只有修改的时候记录)
    auditStatus: number; // 审核状态（0 草稿 1 审核中 2 审核完成）
    finalAuditStatus: number; // 最终审核状态：0 待审核 1 审核通过 2 审核不通过
    auditTime: string | Dayjs; // 审核完成时间
    auditor: string; // 审核人
    auditComment: string; // 审核意见
    metadata: string; // 其他参数
  }
}

/** 查询岗位情况业务信息分页 */
export function getBusinessPostExperiencePage(
  data: PageParam,
  desensitize: boolean,
  encrypt: boolean,
) {
  return requestClient.post<
    PageResult<PerBusinessPostExperienceApi.BusinessPostExperience>
  >('/per/business-post-experience/page', data, {
    desensitize,
    encrypt,
  });
}

/** 查询岗位情况业务信息详情 */
export function getBusinessPostExperience(id: number) {
  return requestClient.get<PerBusinessPostExperienceApi.BusinessPostExperience>(
    `/per/business-post-experience/get?id=${id}`,
  );
}

/** 新增岗位情况业务信息 */
export function createBusinessPostExperience(
  data: PerBusinessPostExperienceApi.BusinessPostExperience,
) {
  return requestClient.post('/per/business-post-experience/create', data);
}

/** 修改岗位情况业务信息 */
export function updateBusinessPostExperience(
  data: PerBusinessPostExperienceApi.BusinessPostExperience,
) {
  return requestClient.put('/per/business-post-experience/update', data);
}

/** 删除岗位情况业务信息 */
export function deleteBusinessPostExperience(id: number) {
  return requestClient.delete(`/per/business-post-experience/delete?id=${id}`);
}

/** 批量删除岗位情况业务信息 */
export function deleteBusinessPostExperienceList(ids: number[]) {
  return requestClient.delete(
    `/per/business-post-experience/delete-list?ids=${ids.join(',')}`,
  );
}

/** 导出岗位情况业务信息 */
export function exportBusinessPostExperience(params: any) {
  return requestClient.download('/per/business-post-experience/export-excel', {
    params,
  });
}

/** 根据业务主表id去查询业务数据 */
export function getPostExperienceBusiId(data: any) {
  return requestClient.post<PerBusinessPostExperienceApi.BusinessPostExperience>(
    `/per/business-edu-experience/getPostExperienceBusiId`,
    data,
  );
}

/** 获取当前登录人岗位信息信息 */
export function getCurrentPostExperiences(
  data,
  desensitize: boolean,
  encrypt: boolean,
) {
  return requestClient.post<
    List<PerBusinessPostExperienceApi.BusinessPostExperience>
  >('/per/business-post-experience/getCurrentPostExperiences', data, {
    desensitize,
    encrypt,
  });
}
